"""
spark数据输出，输出到文件中
"""
from pyspark import SparkConf, SparkContext

conf = SparkConf().setMaster("local[*]").setAppName("test_spark_app")
# 设置全局并行度为1,固定分区为1
# conf.set("spark.default.parallelism", "1")
sc = SparkContext(conf=conf)

# 准备三份数据 numSlices 设置分片数
rdd1 = sc.parallelize([1, 2, 3, 4, 5], numSlices=1)
rdd2 = sc.parallelize([("曹操", 20), ("刘备", 30), ("孙权", 40)], numSlices=1)
rdd3 = sc.parallelize([[1, 2, 3], [4, 5, 6], [7, 8, 9]], numSlices=1)

# 输出数据到文件中
path1 = "/Users/dongjian/Documents/学习/python-learn-资料/output1"
path2 = "/Users/dongjian/Documents/学习/python-learn-资料/output2"
path3 = "/Users/dongjian/Documents/学习/python-learn-资料/output3"
rdd1.saveAsTextFile(path1)
rdd2.saveAsTextFile(path2)
rdd3.saveAsTextFile(path3)
